
<html>
	<head>
	</head>
	<body>
		<form method="get" action="<?php echo $_SERVER['PHP_SELF'] ; ?>" >
			<table>
				<tr>
					<td>
						LAT :
					</td> 
					<td>
						<input type="text" name="lat">
					</td>
				</tr>
				<tr>
					<td>
						LNG :
					</td>
					<td>
						<input type="text" name="lng">
					</td>
				</tr>
				<tr>
					<td>
						Address :
					</td>
					<td>
						<input type="text" name="address">
					</td>
				</tr>
				<tr>
					<td>
						<input type="submit" name="go" value="Find">
					</td>
					<td>
						<input type="button"  value="Reset" onclick="location.href='maps.php'">
					</td>
				</tr>
			</table>
		</form>

		<?php
			function checkResult($status){
				if ( $status == "ZERO_RESULTS") {
					echo " NO RESULTS<br/>";
				}
			}
			if (isset($_GET['go'])){
				if ($_GET['lat']!= "" && $_GET['lng'] != "") {
					if (is_numeric($_GET['lat']) && is_numeric($_GET['lng'])){
						$json = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?latlng=".$_GET['lat'].",".$_GET['lng']."&sensor=true");
						$map =json_decode($json);
						
						echo "LAT  :".$_GET['lat'];
						echo "<br/>LNG :".$_GET['lng']."<br/><br/>";
						echo "<br/>ADDRESS : ".$map->results[1]->formatted_address;
						checkResult($map->status);		
					} else {
						echo  "<br/> YOU SHOULD ENTER VALID COORDINATES <br/>";
					}
				} elseif  ($_GET['address'] != "") {
					$address = str_replace(" ","+",$_GET['address']);
					$json = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=".$address."&sensor=true");
					$map = json_decode($json);
					
					echo "Search : ".$_GET['address']."<br/><br/>";
					foreach ($map->results as $value) {
						echo "LAT :".$value->geometry->location->lat;
						echo "<br/>LNG :".$value->geometry->location->lng;
						echo "<br/>ADDRESS : ".$value->formatted_address."<br/><br/><br/><br/>";
					}
					checkResult($map->status);

				} else {
					echo "<br/> YOU SHOULD ENTER SOMETHING <br/>";
				}


			}




		?>


	</body>
</html>
